package list

// 递归
func reverseList(head *ListNode) *ListNode {

	if head == nil || head.Next == nil {
		return head
	}

	newHead := reverseList(head.Next)
	next := head.Next
	head.Next = nil
	next.Next = head

	return newHead

}

// 迭代
func reverseList2(head *ListNode) *ListNode {

	var temp *ListNode
	cur := head
	for cur != nil {
		next := cur.Next
		cur.Next = temp
		temp = cur
		cur = next
	}

	return temp

}
